<template>
  <div class="center">
    <notice></notice>
    <div class="user_info_card">
      <div class="card_top">
        <img :src="centerInfo.avatar">
        <div>
          <p>{{centerInfo.nickname}}</p>
        </div>
        <van-icon name="setting-o" size=".41rem" class="setting_icon" @click="toSetting"/>
      </div>
    </div>
    <div class="balance_card">
      <div class="balance">
        <span>{{centerInfo.now_money}}</span>
        <p>我的余额</p>
      </div>
      <div class="integral">
        <span>{{centerInfo.integral}}</span>
        <p>当前积分</p>
      </div>
      <div class="ticket">
        <span>{{centerInfo.couponCount}}</span>
        <p>红包卡券</p>
      </div>
    </div>
    <div class="order_card">
      <div class="order_card_header">
        <div>我的订单</div>
        <span></span>
        <van-icon name="arrow" size=".22rem" class="order_card_header_icon"/>
      </div>
      <div class="order_item">
        <van-grid>
          <van-grid-item :icon="$img('dfk.png')" @click="toNext('/shopOrder?showView=0')" :info="centerInfo.orderStatusNum && centerInfo.orderStatusNum.unpaid_count > 0  ? centerInfo.orderStatusNum.unpaid_count : ''" text="待付款" />
          <van-grid-item :icon="$img('dfx.png')" @click="toNext('/shopOrder?showView=1')" :info="centerInfo.orderStatusNum && centerInfo.orderStatusNum.share_count > 0  ? centerInfo.orderStatusNum.share_count : ''" text="待分享" />
          <van-grid-item :icon="$img('dfh.png')" @click="toNext('/shopOrder?showView=2')" :info="centerInfo.orderStatusNum && centerInfo.orderStatusNum.unshipped_count > 0  ? centerInfo.orderStatusNum.unshipped_count : ''" text="待发货" />
          <van-grid-item :icon="$img('dsh.png')" @click="toNext('/shopOrder?showView=3')" :info="centerInfo.orderStatusNum && centerInfo.orderStatusNum.received_count > 0  ? centerInfo.orderStatusNum.received_count : ''" text="待收货" />
          <van-grid-item :icon="$img('dpj.png')" @click="toNext('/shopOrder?showView=4')" :info="centerInfo.orderStatusNum && centerInfo.orderStatusNum.evaluated_count > 0  ? centerInfo.orderStatusNum.evaluated_count : ''" text="待评价" />
        </van-grid>
      </div>
    </div>
    <div class="convenient">
      <van-grid>
        <van-grid-item :icon="$img('spsc.png')" text="商品收藏" @click="toNext('/shopCollcet')"/>
        <van-grid-item :icon="$img('dpsc.png')" text="店铺收藏" @click="toNext('/shoplike')"/>
        <van-grid-item :icon="$img('wdzj.png')" text="我的足迹" @click="toNext('/myFootPrint')"/>
        <van-grid-item :icon="$img('shdz.png')" text="收货地址" @click="toNext('/myAddress')"/>
        <van-grid-item :icon="$img('gfkf.png')" text="官方客服" @click="call()"/>
      </van-grid>
    </div>
    <div class="adv" v-if="advImg !== ''">
      <van-image :src="advImg">
        <template v-slot:loading>
          <van-loading type="spinner" size="20" />
        </template>
      </van-image>
    </div>
    <div class="center_card">
      <div @click="routePath">
        <img :src="$img('shzx.png')">
        <span>商户中心</span>
      </div>
      <div @click="toUser">
        <img :src="$img('fxzx.png')">
        <span>分享中心</span>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  data () {
    return {
      fileList: [],
      centerInfo: '',
      advImg: ''
    }
  },
  methods: {
    ...mapMutations(['SET_TOKEN', 'SET_UINFO']),
    afterRead (file) {
      this.$upload(file)
    },
    getUinfo () {
      this.$axios.get(`/api/user?_=${Math.random() * Math.random()}`).then(res => {
        if (res.status === 200) {
          this.userInfo = res.data
          this.centerInfo = res.data
          this.$store.commit('SET_UINFO', res.data)
          localStorage.setItem('uinfo', JSON.stringify(res.data))
        }
      })
    },
    getAdv () {
      this.$axios.get('/api/store/adv', {
        type: 'user_center'
      }).then(res => {
        if (res.status === 200) {
          if (res.data.length > 0) {
            this.advImg = res.data.cover
          }
        }
      })
    },
    toNext (url) {
      this.$router.push(url)
    },
    toSetting () {
      this.$router.push('/setting')
    },
    routePath () {
      if (this.centerInfo.is_mer || this.centerInfo.mer_id > 0) {
        this.$router.push('/business')
      } else {
        this.$router.push('/join')
      }
    },
    toUser () {
      this.$router.push('/shareCenter')
    },
    call () {
      window.location.href = `tel: ${this.userInfo.serveCallNum}`
    }
  },
  created () {
    this.getUinfo()
    this.getAdv()
  }
}
</script>

<style lang="scss">
.center{
  background: #F6F6F6;
  height: 100%;
  .user_info_card{
    margin-top: .34rem;
    .card_top{
      display: flex;
      img{
        width: 1.2rem;
        height: 1.2rem;
        flex: 0 1 auto;
        margin-left: .32rem;
        margin-right: .32rem;
        border-radius: 1.2rem;
      }
      div{
        flex: 1;
        color: #333333;
        font-size: .32rem;
        margin-top: .12rem;
        p{
          width: 4.64rem;
          overflow: hidden;
          text-overflow:ellipsis;
          white-space: nowrap;
        }
      }
      .setting_icon{
        flex: 0 1 auto;
        margin-right: .36rem;
        margin-top: .12rem;
      }
    }
  }
  .balance_card{
    margin: .44rem .6rem .24rem;
    display: flex;
    justify-content: space-between;
    div{
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    span{
      color: #111010;
      font-size: .28rem;
      font-weight: bold;
      margin-bottom: .14rem;
    }
    p{
      color: #333333;
      font-size: .2rem;
    }
  }
  .order_card{
    background: #ffffff;
    margin: 0 .16rem;
    padding: .16rem 0 0;
    border-radius: .08rem;
    .order_card_header{
      margin: 0 .2rem;
      display: flex;
      align-items: center;
      border-bottom: .02rem solid #f6f6f6;
      padding-bottom: .16rem;
      div{
        color: #111010;
        font-size: .24rem;
        font-weight: bold;
        flex: 0 1 auto;
      }
      span{
        font-size: .2rem;
        color: #999999;
        margin-right: .14rem;
        flex: 1;
        text-align: right;
      }
      .order_card_header_icon{
        flex: 0 1 auto;
      }
    }
    .order_item{
      .van-grid-item{
        flex-basis: 20% !important;
      }
      .van-icon__image{
        width: .6rem;
        height: .6rem;
      }
      .van-grid-item__text{
        font-size: .24rem;
        color: #333333;
      }
      [class*=van-hairline]::after{
        border: unset !important;
      }
    }
  }
  .convenient{
    margin: .16rem .16rem 0;
    border-radius: .08rem;
    background: #ffffff;
    .van-grid-item{
      flex-basis: 20% !important;
    }
    .van-icon__image{
      width: .6rem;
      height: .6rem;
    }
    .van-grid-item__text{
      font-size: .24rem;
      color: #333333;
    }
    [class*=van-hairline]::after{
      border: unset !important;
    }
  }
  .center_card{
    margin: .16rem .16rem 0;
    border-radius: .08rem;
    background: #ffffff;
    font-size: .24rem;
    color: #333333;
    padding: 0 .16rem;
    div{
      display: flex;
      align-items: center;
      padding: .24rem 0;
      border-bottom: .02rem solid #f6f6f6;
      img{
        width: .48rem;
        height: .48rem;
        margin-right: .16rem;
      }
    }
    div:last-child{
      border: unset;
    }
  }
  .adv{
    height: 1.86rem;
    display: flex;
    align-items: center;
    padding: .16rem .16rem 0;
    .van-image{
      width: 100%;
      height: 100%;
    }
  }
}
</style>
